package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.ReportInfo;
import com.ruoyi.system.api.domain.StErrorReport;
import com.ruoyi.system.api.domain.StHotAccountReport;
import com.ruoyi.system.api.service.IReportInfoService;
import com.ruoyi.system.api.service.IStHotAccountReportService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * Hot Account Report报告
 *
 * @ClassName AcceptanceReportController.java
 * @date 2020/3/9 8:41 上午
 * @author yzg
 */
@Api(tags="Hot Account Report报告")
@RestController
@RequestMapping("/api/cc/hot/account/report/")
public class HotAccountReportController extends BaseController {

    @Autowired
    private IStHotAccountReportService hotAccountReportService;
    @Autowired
    private IReportInfoService reportInfoService;
    private static final Logger log = LoggerFactory.getLogger(HotAccountReportController.class);
    /**
     *  添加 Hot Account Report
     *
     * @param hotAccountReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/7 1:38 下午
     */
    @Log(title = "添加 Hot Account Report", businessType = BusinessType.INSERT)
    @PostMapping("addHoatAccountReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加 Hot Account Report", httpMethod = "POST", notes = "添加 Hot Account Report")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addHoatAccountReport(@RequestBody StHotAccountReport hotAccountReport){
        try {
            return hotAccountReportService.addHoatAccountReport(hotAccountReport);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  修改 Hot Account Report
     *
     * @param hotAccountReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/7 1:39 下午
     */
    @Log(title = "修改 Hot Account Report", businessType = BusinessType.UPDATE)
    @PostMapping("updateHoatAccountReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "修改 Hot Account Report", httpMethod = "POST", notes = "修改 Hot Account Report")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateHoatAccountReport(@RequestBody StHotAccountReport hotAccountReport){
        try {
            return hotAccountReportService.updateHoatAccountReport(hotAccountReport);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  提交 Hot Account Report
     *
     * @param id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/7 1:39 下午
     */
    @RepeatSubmit
    @Log(title = "提交 Hot Account Report", businessType = BusinessType.UPDATE)
    @GetMapping("hoatAccountReportSubmit")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "提交 Hot Account Report", httpMethod = "GET", notes = "提交 Hot Account Report")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "ErrorReport主键ID", name = "id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "提交工程师id", name = "enginnerId", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> hoatAccountReportSubmit(@RequestParam Long id, @RequestParam Long enginnerId){
        try {
            return hotAccountReportService.hoatAccountReportSubmit(id, enginnerId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看 Hot Account Report
     *
     * @param id
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/7 1:40 下午
     */
    @GetMapping("detailHoatAccountReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看 Hot Account Report", httpMethod = "GET", notes = "查看 Hot Account Report")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "ErrorReport主键ID", name = "id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> detailHoatAccountReport(@RequestParam(value="id",required=true) String id){
        try {
            return hotAccountReportService.detailHoatAccountReport(Long.parseLong(id));
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看HotReport列表
     *
     * @param serviceNo
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author sunjy
     * @date 2020年3月13日15:42:42
     */
    @GetMapping("selectHotReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看HotReport列表", httpMethod = "GET", notes = "查看HotReport列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "计划id", name = "planId", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师姓名", name = "fseName", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "创建时间 （YYYY-MM-dd）", name = "createTime", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> selectHotReport(@RequestParam(value="serviceNo",required=false) String serviceNo,
                                               @RequestParam(value="enginnerId",required=false) Long enginnerId,
                                               @RequestParam(value="planId",required=false) Long planId,
                                               @RequestParam(value="fseName",required=false) String fseName,
                                               @RequestParam(value="createTime",required=false) String createTime) {
        try {
            List<ReportInfo> list = new ArrayList<>();
            ReportInfo reportInfo = new ReportInfo();
            reportInfo.setServiceNo(serviceNo);
            reportInfo.setEnginnerId(enginnerId);
            reportInfo.setPlanId(planId);
            reportInfo.setFseName(fseName);
            if (StringUtils.isNotEmpty(createTime)) {
                Date date = DateUtils.parseDate(createTime);
                if (date != null){
                    reportInfo.setStartTime(createTime + " 00:00:00");
                    reportInfo.setEndTime(createTime + " 23:59:59");
                }
            }
            reportInfo.setRelServiceNo(3L);
            list = hotAccountReportService.selectStHotAccountReportList(reportInfo);
            return new ResponseWithData<>().success(list).code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     *  查看CCHotReport列表
     *
     * @param serviceNo
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author bairuihua
     * @date 2020年5月23日15:42:42
     */
    @GetMapping("getCCHotReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看HotReport列表", httpMethod = "GET", notes = "查看HotReport列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "serviceNo", name = "serviceNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getCCHotReport(@RequestParam(value="serviceNo",required=true) String serviceNo,
                                               @RequestParam(value="enginnerId",required=true) String enginnerId,
                                              @RequestParam(value="reportNo",required=true) String reportNo
                                             ) {
        try {

            Map<String,String> paraMap = new HashMap();
            paraMap.put("report_guid",reportNo);
            paraMap.put("service_no",serviceNo);
            paraMap.put("enginner_id",enginnerId);
            return   hotAccountReportService.getStHotAccountReportList(paraMap);

        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     *  删除HotAccountReport报告
     *
     * @param id
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/4/20 4:16 下午
     */
    @Log(title = "删除HotAccountReport报告", businessType = BusinessType.DELETE)
    @GetMapping("delHotAccountReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "删除HotAccountReport报告", httpMethod = "GET", notes = "删除HotAccountReport报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "报告id", name = "id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "工程师ID", name = "enginnerId", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> delHotAccountReport(@RequestParam("id") Long id, @RequestParam("enginnerId") Long enginnerId) {
        try {
            return hotAccountReportService.delHotAccountReport(id, enginnerId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     * 修改ErrorReport报告状态
     *
     * @param id
     * @param enginnerId
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/4/20 2:17 下午
     */
    @Log(title = "修改HotReport报告", businessType = BusinessType.UPDATE)
    @GetMapping("updateStatus")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "修改HotReport报告", httpMethod = "GET", notes = "修改HotReport报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "请求编号", name = "reptNo", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "status", required = true, dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateStatus(@RequestParam("reptNo") String reptNo, @RequestParam("status") String status) {
        try {
            ReportInfo reportInfo = new ReportInfo();
            reportInfo.setReportNo(reptNo);
            reportInfo.setStatus(status);
            reportInfoService.updateStReportInfoByReportNo(reportInfo);
            return new ResponseWithData().success().msg("更新成功").code(200);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
}
